package br.fagoc.easyds.ui.jgraph;

import br.fagoc.easyds.util.JGraphFactory;

import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxICell;
import com.mxgraph.view.mxGraph;

public class GraphEdgeManipulator {
	
	private mxGraph graph;

	public GraphEdgeManipulator(mxGraph graph){
		this.graph = graph;
	}
	
	public mxICell createEdge(mxCell source, mxCell target){
		return (mxICell) graph.createEdge(graph.getDefaultParent(), null, null, source, target, JGraphFactory.EDGE_STYLE);
	}
	
	public void drawEdge(mxICell edge, mxCell source, mxCell target){
		graph.addEdge(edge, graph.getDefaultParent(), source, target, 1);
	}
	
	public mxICell drawEdge(mxCell source, mxCell target){
		mxICell aresta = createEdge(source, target);
		graph.addEdge(aresta, graph.getDefaultParent(), source, target, 1);
		
		return aresta;
	}
	
	public void removeEdge(mxCell graphCell, mxICell edge){
		graphCell.removeEdge(edge, false);
	}
}
